<?xml version="1.0" encoding="UTF-8"?>
<!DOCTYPE mapper PUBLIC "-//mybatis.org//DTD Mapper 3.0//EN" "http://mybatis.org/dtd/mybatis-3-mapper.dtd">
<mapper namespace="${mapperUrl}.${mapperName}">
	<resultMap id="BaseResultMap" type="${entityUrl}.${entityName}">
      <#list cis as ci1>
	      <result column="${ci1.fieldName}" property="${ci1.property}" jdbcType="${ci1.jdbcType?upper_case}"/>
      </#list>
	</resultMap>
	<sql id="addLimit">
		<if test="start!=null"> limit <#noparse>#{start},#{limit}</#noparse> </if>
	</sql>

	<sql id="filters">
		<where>
        <#list cis as ci1>
	        <if test="${ci1.property}!=null"> and `${ci1.fieldName}`=<#noparse>#{</#noparse>${ci1.property}<#noparse>}</#noparse> </if>
        </#list>
		</where>
	</sql>

	<insert id="insert" >
		insert into ${table} (<#list cis as ci1>`${ci1.fieldName}`<#if ci1_has_next>,</#if></#list>) values (<#list cis as ci2><#noparse>#{</#noparse>${ci2.property}<#noparse>}</#noparse><#if ci2_has_next>,</#if></#list>)
	</insert>


	<delete id="deleteByPrimaryKey">
		delete from ${table}  where ${primaryKeyFieldName}=<#noparse>#{</#noparse>${primaryKeyPropertyName}<#noparse>};</#noparse>
	</delete>

	<update id="updateByPrimaryKeySelective" >
		update ${table}
		<trim prefix="set" suffixOverrides=",">
        <#list cis as ci1>
					<if test="${ci1.property}!=null">`${ci1.fieldName}`=<#noparse>#{</#noparse>${ci1.property}<#noparse>}</#noparse> </if>
        </#list>
		</trim>
		where ${primaryKeyFieldName}=<#noparse>#{</#noparse>${primaryKeyPropertyName}<#noparse>};</#noparse>
	</update>

	<select id="selectByPrimaryKey"  resultMap="BaseResultMap">
		select * from ${table} where ${primaryKeyFieldName}=<#noparse>#{</#noparse>${primaryKeyPropertyName}<#noparse>};</#noparse>
	</select>

	<select id="getList" resultType="java.util.List" resultMap="BaseResultMap">
		select * from ${table} <include refid="filters"></include>  order by ${primaryKeyFieldName} <include refid="addLimit"></include>;
	</select>

	<select id="count" resultType="java.lang.Integer">
		select count(*) from ${table} <include refid="filters"></include>;
	</select>

</mapper>